package cn.hotel.service;

import cn.hotel.dao.RoomKeeperDao;
import cn.hotel.pojo.RoomKeeper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RoomKeeperServiceImpl implements RoomKeeperService{
    cn.hotel.dao.RoomKeeper keeper = new RoomKeeperDao();
    @Override
    public Map<String, Object> som(int room, int atPresent, int sum) {
        Map<String ,Object> objectMap = new HashMap<>();
        try {
            int num  = (atPresent - 1) * sum;
            List<cn.hotel.pojo.RoomKeeper> roomKeepers = keeper.rkl(room,num,sum);
            if(roomKeepers != null && roomKeepers.size() > 0){
                objectMap.put("flag","1");
                objectMap.put("mag","查询成功");
                objectMap.put("data",roomKeepers);
            }else {
                objectMap.put("flag","0");
                objectMap.put("mag","查询失败");
            }
            return objectMap;
        } catch (Exception exception) {
            exception.printStackTrace();
            objectMap.put("flag","-1");
            objectMap.put("mag","程序异常");
        }
        return objectMap;
    }

    @Override
    public Map<String, Object> roomKeeper(int room) {
        Map<String ,Object> objectMap = new HashMap<>();
        try {
            int num = keeper.roomKeeper(room);
            if(num > 0){
                objectMap.put("flag","1");
                objectMap.put("mag","查询成功");
                objectMap.put("data",num);
            }else {
                objectMap.put("flag","0");
                objectMap.put("mag","查询失败");
            }
            return objectMap;
        } catch (Exception exception) {
            exception.printStackTrace();
            objectMap.put("flag","-1");
            objectMap.put("mag","程序异常");
        }
        return objectMap;
    }

    @Override
    public Map<String, Object> addRoomKeeper(RoomKeeper roomKeeper) {
        Map<String ,Object> objectMap = new HashMap<>();
        try {
            int num = keeper.addRoomKeeper(roomKeeper);
            if(num > 0){
                objectMap.put("flag","1");
                objectMap.put("mag","添加成功");
                objectMap.put("data",num);
            }else {
                objectMap.put("flag","0");
                objectMap.put("mag","添加失败");
            }
            return objectMap;
        } catch (Exception exception) {
            exception.printStackTrace();
            objectMap.put("flag","-1");
            objectMap.put("mag","程序异常");
        }
        return objectMap;
    }

    @Override
    public Map<String, Object> deleteRoomKeeper(int room) {
        Map<String ,Object> objectMap = new HashMap<>();
        try {
            int num = keeper.deleteRoomKeeper(room);
            if(num > 0){
                objectMap.put("flag","1");
                objectMap.put("mag","删除成功");
                objectMap.put("data",num);
            }else {
                objectMap.put("flag","0");
                objectMap.put("mag","删除失败");
            }
            return objectMap;
        } catch (Exception exception) {
            exception.printStackTrace();
            objectMap.put("flag","-1");
            objectMap.put("mag","程序异常");
        }
        return objectMap;
    }

    @Override
    public Map<String, Object> modification(RoomKeeper roomKeeper) {
        return null;
    }

    @Override
    public Map<String, Object> numType(int num) {
        Map<String ,Object> objectMap = new HashMap<>();
        try {
            int nums = keeper.numType(num);
            if(nums > 0){
                objectMap.put("flag","1");
                objectMap.put("mag","查询成功");
                objectMap.put("data",num);
            }else {
                objectMap.put("flag","0");
                objectMap.put("mag","查询失败");
            }
            return objectMap;
        } catch (Exception exception) {
            exception.printStackTrace();
            objectMap.put("flag","-1");
            objectMap.put("mag","程序异常");
        }
        return objectMap;
    }
}
